package com.example.prison.mapper;

import com.example.prison.entity.DepartmentManagement;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.prison.entity.vo.DepartmentManagementVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
* @author jiang
* @description 针对表【department_management】的数据库操作Mapper
* @createDate 2024-06-03 10:42:06
* @Entity com.example.prison.entity.DepartmentManagement
*/
@Mapper
public interface DepartmentManagementMapper extends BaseMapper<DepartmentManagement> {

    @Select("<script>select * from department_management " +
            " <where> " +
            " <if test=\"departName != null and departName != ''\">and depart_name like concat('%',#{departName},'%') </if> " +
            " <if test=\"departLevel != null and departLevel != ''\">and depart_level like concat('%',#{departLevel},'%') </if> " +
            " </where> " +
            "order by depart_id desc</script>")
    List<DepartmentManagement> get(String departName, String departLevel);

    @Insert("insert into department_management(depart_name, father_depart, depart_level) values (#{departName}, #{fatherDepart}, #{departLevel})")
    int add(DepartmentManagement department);

    @Delete("<script>delete from department_management where depart_id in <foreach collection=\"ids\" item=\"item\" open=\"(\" separator=\",\" close=\")\">#{item} </foreach> </script>")
    void deleteDepartment(@Param("ids") Integer[] ids);

//    @Update("update department_management set depart_name=#{department.departName},father_depart=#{department.fatherDepart},depart_level=#{department.departLevel} where depart_id = #{departId}")
    @Update({"<script> UPDATE department_management",
            "<set>",
            "<if test='department.departName != null'>depart_name = #{department.departName},</if>",
            "<if test='department.fatherDepart != null'>father_depart = #{department.fatherDepart},</if>",
            "<if test='department.departLevel != null'>depart_level = #{department.departLevel},</if>",
            "</set>",
            "where depart_id = #{departId} </script>"})
    int updateDepartment(DepartmentManagement department,Integer departId);

    @Select("select * from department_management where depart_id=#{departId}")
    DepartmentManagement getById(@Param("departId") Integer departId);

    @Select("select * from department_management where depart_name like concat('%',#{departName},'%') order by depart_id desc")
    List<DepartmentManagement> getByName(@Param("departName") String departName);

    @Select("select * from department_management where depart_name =#{departName} order by depart_id desc")
    List<DepartmentManagement> getListOneByName(@Param("departName") String departName);

    @Select("select * from department_management where depart_name=#{departName}")
    DepartmentManagement getOneByName(@Param("departName") String departName);

    @Select("select * from department_management where depart_level=#{departLevel} order by depart_id desc")
    List<DepartmentManagement> getDepartByLevel(@Param("departLevel") String departLevel);

    @Select("select * from department_management where depart_level=#{departLevel} order by depart_id desc")
    List<DepartmentManagementVO> getByLevel(@Param("departLevel") String departLevel);

}




